package yf.mall.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.util.*;

import org.springframework.transaction.annotation.Transactional;
import yf.mall.dao.OrderUnionDao;
import yf.mall.entity.OrderUnionEntity;
import yf.mall.service.OrderUnionService;
import com.yf.service.impl.BaseServiceImpl;

/**
 * 联合订单Service实现类
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Tue Jun 30 11:45:42 CST 2020
 */
@Service
public class OrderUnionServiceImpl extends BaseServiceImpl<OrderUnionEntity> implements OrderUnionService {

    private OrderUnionDao orderUnionDao;


    @Autowired
    public void setDao(OrderUnionDao orderUnionDao) {
        this.orderUnionDao = orderUnionDao;
        super.setBaseDao(orderUnionDao);
    }


    /**
     *
     *   @Override
     *     public List<UserVo> queryListVo(UserVo userVo) {
     *         return userDao.queryListVo(userVo);
     *     }
     *
     *     @Override
     *     public UserVo getVo(Long id) {
     *         return userDao.getVo(id);
     *     }

     @Override List<OrderUnionVo> queryListVo(OrderUnionVo orderUnionVo){
     return orderUnionDao.queryListVo(orderUnionVo);
     }

     @Override OrderUnionVo getVo(Long id){
     return orderUnionDao.getVo(id);
     }
     **/


    /**内部方法**/


    /**
     * 外部方法实现
     **/

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void union(String unionNo, List<String> orderNos) {
        String orderNo = String.join("_", orderNos);
        OrderUnionEntity orderUnionEntity = new OrderUnionEntity(unionNo, orderNo, new Date());
        save(orderUnionEntity);
    }

    @Override
    public List<String> findByUnionNo(String unionNo) {
        String orderNos = orderUnionDao.findByUnionNo(unionNo);
        if (orderNos == null) {
            return new ArrayList<>();
        }
        return Arrays.asList(orderNos.split("_"));
    }
}
